﻿using System;
using Core.Framework.Model.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace Core.DataAccess.Model.Project.Comment
{
    /// <summary>
    /// 评论模块
    /// </summary>
    public partial class ProjectCommentContext : DbContext
    {
        public ProjectCommentContext()
        {

        }

        public ProjectCommentContext(DbContextOptions<ProjectCommentContext> options)
            : base(options)
        {
        }

        public virtual DbSet<CommentAttribute> CommentAttribute { get; set; }
        public virtual DbSet<CommentList> CommentList { get; set; }
        public virtual DbSet<CommentReply> CommentReply { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {

            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer(CoreStartupHelper.GetConnectionValue("Comment_SqlServerConnection"));
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<CommentAttribute>(entity =>
            {
                entity.ToTable("Comment_Attribute");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.CommentKey).HasColumnName("comment_key");

                entity.Property(e => e.Extend)
                    .HasColumnName("extend")
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.ReplyKey)
                    .HasColumnName("reply_key")
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.Type).HasColumnName("type");

                entity.Property(e => e.UserKey).HasColumnName("user_key");
            });

            modelBuilder.Entity<CommentList>(entity =>
            {
                entity.ToTable("Comment_List");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Check).HasColumnName("check");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.Extend)
                    .HasColumnName("extend")
                    .IsUnicode(false);

                entity.Property(e => e.InformationKey).HasColumnName("information_key");

                entity.Property(e => e.ProjectToken)
                    .HasColumnName("project_token")
                    .HasMaxLength(21)
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Relevant)
                    .HasColumnName("relevant")
                    .HasMaxLength(1000)
                    .IsUnicode(false);

                entity.Property(e => e.UserKey).HasColumnName("user_key");
            });

            modelBuilder.Entity<CommentReply>(entity =>
            {
                entity.ToTable("Comment_Reply");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Check).HasColumnName("check");

                entity.Property(e => e.CommentKey).HasColumnName("comment_key");

                entity.Property(e => e.CommentUserKey).HasColumnName("comment_user_key");

                entity.Property(e => e.Content)
                    .HasColumnName("content")
                    .IsUnicode(false);

                entity.Property(e => e.Extend)
                    .HasColumnName("extend")
                    .IsUnicode(false);

                entity.Property(e => e.RegTime)
                    .HasColumnName("reg_time")
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Relevant)
                    .HasColumnName("relevant")
                    .HasMaxLength(1000)
                    .IsUnicode(false);

                entity.Property(e => e.ReplyUserKey).HasColumnName("reply_user_key");
            });
        }
    }
}
